use serde::{Deserialize, Serialize};

#[derive(Clone, Debug,Deserialize, Serialize, sqlx::FromRow)]
pub struct ArticleSummary {
    pub id: i32,
    pub title: String,
    pub categoryId: Option<i32>,
    pub summary: String,
    pub path: String,
    //pub createOn: NaiveDateTime,
    pub createBy: String,
    pub view_amount: i32,
}

impl ArticleSummary {
    pub fn new(title: &str, summary: &str, path: &str) -> Self {
        ArticleSummary {
            id: 0,
            title: title.to_string(),
            categoryId: Some(0),
            summary: summary.to_string(),
            path: path.to_string(),
            //createOn: Utc::now().naive_utc(),
            createBy: "Admin".to_string(),
            view_amount:0,
        }
    }
}

#[cfg(test)]
mod test {
    use super::*;

    #[test]
    fn test_new() {
        let article_sumary = ArticleSummary::new("test_title", "test_summary" ,"");
        assert_eq!(article_sumary.title, "test_title");
    }
}
